define([
    'TreeTable', 'Switch', 'Pagination', 'common', 'data/treeData', 'breadNav', 'Step', 'Popover', 'text!data/menu.json'
], function(TreeTable, Switch, Pagination, common, treeData, BreadNav, Step, Popover, menuJson) {
    'use strict';
    var selectKeys = ['公司级看板_查询', '数据同步_重置', '用户管理_重置', '角色管理_查询', '角色管理_重置', '角色管理_新增'];

    var columns = [
        {
            title: "菜单类别",
            width: "100px"
        },
        {
            title: "一级菜单",
            width: "200px"
        },
        {
            title: "二级菜单",
            width: "200px"
        },
        // {
        //     title: "三级菜单",
        //     width: "200px"
        // },
        {
            title: "功能",
            width: "auto"
        }
    ];

    var currentPage = {
        showTreeTable: function(){
            new TreeTable({
                id: "myTreeTable",
                treeData: treeData,
                showTips: true,
                tipsMsg:"超级管理员拥有所有权限，不可修改！",
                // lastMode: "vertical",
                checkAll:false,
                showLast: true,
                columns: columns,
                key: "key",
                titleFixed: true,
                height: 300,
                selectKeys: selectKeys
            });
        },
        showMySwitch: function(){
            var mySwitch = new Switch({
                id: "mySwitch",
                value: false,
                disabled: false,
                onChange: function(value){
                    console.log('value', value);
                    mySwitch.setValue(!value);
                }
            });
        },
        showLoadingFunc: function(){
            common.setContainerStatus.showLoading('myTreeTable');
            setTimeout(() => {
                common.setContainerStatus.closeLoading('myTreeTable');
                setTimeout(() => {
                    common.setContainerStatus.disabled('myTreeTable');
                    setTimeout(() => {
                        common.setContainerStatus.removeDisabled('myTreeTable');
                    }, 2000);
                }, 1000);
            }, 2000);
        },
        test1: function(){
            var arr = [
                { name: '小米1', value: 1, type: 2, date: '2018-06-07T08:00:01.589Z' },
                { name: '锤子T1', value: 1, type: 2, date: '2018-06-07T08:10:01.589Z' },
                { name: '小米2', value: 1, type: 4, date: '2018-06-07T20:00:01.589Z' },
                { name: '小米2', value: 4, type: 4, date: '2018-06-07T20:10:21.189Z' },
                { name: '小米4', value: 1, type: 4, date: '2018-06-07T08:00:01.560Z' },
                { name: '小米4', value: 2, type: 4, date: '2018-06-07T08:10:31.584Z' },
                { name: '小米6', value: 1, type: 3, date: '2018-06-07T08:00:01.589Z' },
                { name: '小米5s', value: 1, type: 4, date: '2018-06-07T08:00:01.589Z' },
                { name: '锤子T2', value: 1, type: 4, date: '2018-06-07T08:00:01.589Z' },
                { name: '锤子T1', value: 4, type: 4, date: '2018-06-07T08:06:01.589Z' },
                { name: '魅蓝note5', value: 1, type: 4, date: '2018-06-07T08:00:01.589Z' },
                { name: '魅蓝note2', value: 5, type: 4, date: '2018-06-02T08:07:01.589Z' },
                { name: '魅蓝note2', value: 6, type: 4, date: '2018-06-07T08:00:01.589Z' },
                { name: '魅蓝note3', value: 1, type: 4, date: '2018-06-05T08:00:01.589Z' },
                { name: '魅蓝note', value: 1, type: 4, date: '2018-06-07T08:00:01.589Z' },
                { name: 'oppor9', value: 7, type: 4, date: '2018-06-04T08:04:01.588Z' },
                { name: '华为p9', value: 1, type: 4, date: '2018-06-02T08:00:01.577Z' },
                { name: '华为p9', value: 2, type: 4, date: '2018-06-07T08:00:01.110Z' },
                { name: '华为p10', value: 1, type: 1, date: '2018-06-07T08:00:01.534Z' }
            ];
            var result = common.filterData(arr);
            console.log('result', result);
        },
        showPagination: function(){
            var pagination1 = new Pagination({
                id:"myPage",
                pageSize:10,
                totalCount:129,
                pageNum:0,
                sizeSelect:[10,20,30,40,50],
                clickChange:function(pageNum, pageSize){
                    console.log(pageNum, pageSize);
                    /**
                     * 为了ajax请求数据
                     */
                    pagination1.reset({
                        pageNum:pageNum +'',
                        totalCount:150,
                        pageSize:pageSize
                    });
                },
                sizeChange:function(pageNum, pageSize){
                    console.log(pageNum, pageSize);
                    pagination1.reset({
                        pageNum:pageNum +'',
                        totalCount:150,
                        pageSize:pageSize
                    });
                }
            })
        },
        showBreadNav: function(){
            var url = 'modules/permission/userManage.html';
            new BreadNav({
                menus: JSON.parse(menuJson),
                key: "url",
                showKey: "name",
                value: url,
                id:"breadBox",
                onItemClick: function(item){
                    console.log('click item', item);
                }
            });
        },
        showStep: function(){
            var myStep = new Step({
                id:"step",
                source: [{ label:"第一步", value:"1" }, { label:"第二步", value:"2" }, { label:"第三步", value:"3" }]
            })
            myStep.setStepColor('2', '#f73535')
        },
        showPopover: function(){
            new Popover({
                el:"popover",
                content: "<div>123456</div>"
            })
        },
        init: function(){
            currentPage.showTreeTable();
            currentPage.showMySwitch();
            currentPage.showLoadingFunc();
            currentPage.showPagination();
            currentPage.showBreadNav();
            currentPage.showStep();
            currentPage.showPopover();
        }
    }

    return function(){
        return {
            htmlStr: (function(){
                var str = '<div>'
                    + '<div><span class="loading"></span></div>'
                    + '<div id="mySwitch"></div>'
                    + '<div id="myTreeTable"></div>'
                    + '<div id="myPage"></div>'
                    + '<div id="breadBox"></div>'
                    + '<div id="step"></div>'
                    + '<div id="popover"></div>'
                    + '</div>';
                return str;
            })(),
            render: function(){
                currentPage.init();
            }
        }
    }
});